﻿Imports System.Data.SqlClient

Public Class clsPermisosUsuario
    Private mintId As Integer
    Private mintIdUser As Integer
    Private mintIdFrm As Integer
    Private mintPermiso As Integer
    Public Property Id() As Integer
        Get
            Return mintId
        End Get
        Set(ByVal value As Integer)
            mintId = value
        End Set
    End Property
    Public Property IdUser() As Integer
        Get
            Return mintIdUser
        End Get
        Set(ByVal value As Integer)
            mintIdUser = value
        End Set
    End Property
    Public Property IdFrm() As Integer
        Get
            Return mintIdFrm
        End Get
        Set(ByVal value As Integer)
            mintIdFrm = value
        End Set
    End Property
    Public Property Permiso() As Integer
        Get
            Return mintPermiso
        End Get
        Set(ByVal value As Integer)
            mintPermiso = value
        End Set
    End Property
    Public Sub New()
        mintId = 0
        mintIdUser = 0
        mintIdFrm = 0
        mintPermiso = 0
    End Sub
    Public Sub Borrar()

        Call SetSqlInicial("Delete From PermisosUsuarios Where IDPermiso = " & mintId)

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into PermisosUsuarios (" & _
                            "IdUsuario," & _
                            "IdFormulario," & _
                            "Permiso) " & _
                            "VALUES (" & _
                            "@IdUsuario," & _
                            "@IdFormulario," & _
                            "@Permiso) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = InitialConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdPermiso", mintId)
        Command.Parameters.AddWithValue("IdUsuario", mintIdUser)
        Command.Parameters.AddWithValue("IdFormulario", mintIdFrm)
        Command.Parameters.AddWithValue("Permiso", mintPermiso)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el permiso", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
